import mockApi from "@/api/mockApi";
import type {RepairRequestForm} from '@/types/req/repairRequestForm'
import type {RepairRequestQueryForm} from '@/types/req/repairRequestQueryForm'
import type {RepairRequest} from '@/types/resp/repairRequest'
import type {Response} from '@/types/response'
import type {Result} from '@/types/result'
import type {Page} from "@/types/page";

export default class repairRequestApi {
  static repairRequests: RepairRequest[] = [
    {id: 1, buildingId: 1, buildingName: '北区1栋', roomId: 1, roomNumber: '301', description: '阳台的电路短路', requestTime: '2021-02-02 08:30:00', status: 10, staffId: 1, staffName: '赵六', remark: '', finishTime: '2024-02-02 11:00:00', createTime: '2024-02-02 12:12:12', modifyTime: '2024-02-02 13:13:13'},
    {id: 2, buildingId: 2, buildingName: '北区1栋', roomId: 2, roomNumber: '402', description: '马桶旁下水堵了', requestTime: '2022-03-03 08:30:00', status: 20, staffId: 2, staffName: '张三', remark: '已疏通', finishTime: '2024-03-03 11:00:00', createTime: '2024-03-03 12:12:12', modifyTime: '2024-03-03 13:13:13'},
    {id: 3, buildingId: 3, buildingName: '南区1栋', roomId: 3, roomNumber: '501', description: '煤气灶打不着火', requestTime: '2023-02-04 08:30:00', status: 30, staffId: 3, staffName: '李四', remark: '', finishTime: '2024-04-04 11:00:00', createTime: '2024-04-04 12:12:12', modifyTime: '2024-04-04 13:13:13'},
    {id: 3, buildingId: 4, buildingName: '南区2栋', roomId: 4, roomNumber: '503', description: '煤气灶打不着火', requestTime: '2024-02-04 08:30:00', status: 20, staffId: 3, staffName: '李四', remark: '煤气灶坏了', finishTime: '2024-04-04 11:00:00', createTime: '2024-04-04 12:12:12', modifyTime: '2024-04-04 13:13:13'},
    {id: 4, buildingId: 5, buildingName: '东区1栋', roomId: 5, roomNumber: '204', description: '电视机没有信号', requestTime: '2023-04-05 08:30:00', status: 10, staffId: 4, staffName: '王五', remark: '信号暂时终端', finishTime: '2024-05-05 11:00:00', createTime: '2024-05-05 12:12:12', modifyTime: '2024-05-05 13:13:13'},
    {id: 4, buildingId: 6, buildingName: '东区2栋', roomId: 6, roomNumber: '604', description: '网络没有信号了', requestTime: '2024-04-05 08:30:00', status: 30, staffId: 4, staffName: '王五', remark: '', finishTime: '2024-05-05 11:00:00', createTime: '2024-05-05 12:12:12', modifyTime: '2024-05-05 13:13:13'}
  ]

  static async save (repairRequestForm: RepairRequestForm): Promise<Result<void>> {
    console.log('repairRequestApi save params', repairRequestForm)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }

  static async find (repairRequestQueryForm: RepairRequestQueryForm): Promise<Result<Page<RepairRequest>>> {
    console.log('repairRequestApi find params', repairRequestQueryForm)
    const response: Response<Page<object>> = await mockApi.queryPageSuccessfully(repairRequestApi.repairRequests)
    return response.data
  }

  static async findById (id: number): Promise<Result<RepairRequest>> {
    console.log('repairRequestApi findById id', id)
    let target = {}
    for (const a of repairRequestApi.repairRequests) {
      if (a.id === id) {
        target = a
      }
    }
    const response: Response<RepairRequest> = await mockApi.operateSuccessfullyWithData(target)
    return response.data
  }

  static async del (id: number): Promise<Result<void>> {
    console.log('repairRequestApi del id', id)
    const response: Response<void> = await mockApi.operateSuccessfully()
    return response.data
  }
}
